import { PUBLIC_GRAFBASE_API_URL, PUBLIC_GRAFBASE_API_KEY } from '$env/static/public'

export const load = async ({ fetch }) => {
  const fetchInfo = async () => {
    const response = await fetch(PUBLIC_GRAFBASE_API_URL, {
      method: "POST",
      headers: {
        "content-type": "application/json",
        "x-api-key": PUBLIC_GRAFBASE_API_KEY
      },
      body: JSON.stringify({
        query: `{
  postCollection(first: 10) {
    edges {
      node {
        id
        title
        url
      }  }
}
    }`
      })
    })
    const res = await response.json();
    return res.data.postCollection.edges
  }
  return {
    data: fetchInfo()
  }
}